<?php

class Page{
   // 总页数
private	$totalpage;
	// 当前页
private	$selfpage;
	// url地址
private	$url;
	// 每页显示的条数
private	$row;
public function __construct($total,$row=20){
   $this->row=$row;
   $this->totalpage=ceil($total/$row);
   $this->selfpage=isset($_GET['page'])?min(intval($_GET['page']),$this->totalpage):1;
   $this->url=$this->getUrl();
}

// 获得当前的url
private function getUrl(){
    if(isset($_GET['page']))unlink($_GET['page']);
    $url=__WEB__.'?';
    foreach ($_GET as $name => $value) {
    	$url.=$name.'='.$value.'&';
    }
  $url.='page=';
  return $url;

}
//返回SQL语句需要的limit值
public function limit(){
	return ($this->selfpage-1)*$this->row.','.$this->row;
}
// 显示页面
public function show(){
 $html='';
 for($i=1;$i<$this->totalpage;$i++){
 	if($i==$this->selfpage){
 		$html.="<strong>{$i}</strong>";
 	}else{
 		$url=$this->url.$i;
 		$html.="<a href='{$url}'>{$i}</a>";
 	}
 }

return $html;


}

}






?>